import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lmmi/common/index.dart';
import 'package:lmmi/view/share_detail/widget/gift_dialog_widget.dart';

void main() {
  group('Gift Feature Tests', () {
    testWidgets('GiftSuccessDialog displays correctly', (WidgetTester tester) async {
      await tester.pumpWidget(
        MaterialApp(
          home: Scaffold(
            body: GiftSuccessDialog(
              giftName: 'Test Gift',
              giftPrice: '\$4.99',
              recipientName: 'Test User',
            ),
          ),
        ),
      );

      // 验证成功弹窗的关键元素
      expect(find.text('Gift Sent Successfully!'), findsOneWidget);
      expect(find.text('Test Gift'), findsOneWidget);
      expect(find.text('\$4.99'), findsOneWidget);
      expect(find.text('Test User'), findsOneWidget);
      expect(find.text('OK'), findsOneWidget);
    });

    testWidgets('GiftDialogWidget displays gift list', (WidgetTester tester) async {
      await tester.pumpWidget(
        ProviderScope(
          child: MaterialApp(
            home: Scaffold(
              body: GiftDialogWidget(
                recipientId: 'test_user_id',
                recipientName: 'Test User',
              ),
            ),
          ),
        ),
      );

      // 等待动画完成
      await tester.pumpAndSettle();

      // 验证礼物弹窗的关键元素
      expect(find.text('give away'), findsWidgets);
      expect(find.text('Lmmi Pro'), findsOneWidget);
      expect(find.text('\$4.99'), findsWidgets);
    });

    test('MessageType.gift enum exists', () {
      expect(MessageType.gift, isNotNull);
      expect(MessageType.values.contains(MessageType.gift), isTrue);
    });

    test('Gift message creation', () {
      final giftMessageContent = {
        'type': 'gift',
        'senderName': 'Test Sender',
        'giftName': 'Test Gift',
        'giftPrice': '\$4.99',
        'giftImage': 'test_image.png',
        'message': '🎁 Test Sender sent you a gift: Test Gift (\$4.99)',
      };

      expect(giftMessageContent['type'], equals('gift'));
      expect(giftMessageContent['senderName'], equals('Test Sender'));
      expect(giftMessageContent['giftName'], equals('Test Gift'));
      expect(giftMessageContent['giftPrice'], equals('\$4.99'));
      expect(giftMessageContent['message'], contains('🎁'));
    });
  });

  group('Animation Tests', () {
    testWidgets('GiftSuccessDialog has animations', (WidgetTester tester) async {
      await tester.pumpWidget(
        MaterialApp(
          home: Scaffold(
            body: GiftSuccessDialog(
              giftName: 'Test Gift',
              giftPrice: '\$4.99',
              recipientName: 'Test User',
            ),
          ),
        ),
      );

      // 验证动画组件存在
      expect(find.byType(AnimationController), findsWidgets);
      expect(find.byType(ScaleTransition), findsOneWidget);
      expect(find.byType(FadeTransition), findsOneWidget);
    });

    testWidgets('GiftDialogWidget has slide and scale animations', (WidgetTester tester) async {
      await tester.pumpWidget(
        ProviderScope(
          child: MaterialApp(
            home: Scaffold(
              body: GiftDialogWidget(
                recipientId: 'test_user_id',
                recipientName: 'Test User',
              ),
            ),
          ),
        ),
      );

      // 验证动画组件存在
      expect(find.byType(SlideTransition), findsOneWidget);
      expect(find.byType(ScaleTransition), findsWidgets);
      expect(find.byType(AnimatedContainer), findsWidgets);
      expect(find.byType(AnimatedSwitcher), findsWidgets);
    });
  });

  group('User Experience Tests', () {
    testWidgets('Gift selection shows visual feedback', (WidgetTester tester) async {
      await tester.pumpWidget(
        ProviderScope(
          child: MaterialApp(
            home: Scaffold(
              body: GiftDialogWidget(
                recipientId: 'test_user_id',
                recipientName: 'Test User',
              ),
            ),
          ),
        ),
      );

      await tester.pumpAndSettle();

      // 查找礼物卡片
      final giftCards = find.byType(GestureDetector);
      expect(giftCards, findsWidgets);

      // 点击第二个礼物卡片
      if (giftCards.evaluate().length > 1) {
        await tester.tap(giftCards.at(1));
        await tester.pumpAndSettle();

        // 验证价格更新
        expect(find.byType(AnimatedSwitcher), findsWidgets);
      }
    });

    testWidgets('Processing state shows loading indicator', (WidgetTester tester) async {
      await tester.pumpWidget(
        ProviderScope(
          child: MaterialApp(
            home: Scaffold(
              body: GiftDialogWidget(
                recipientId: 'test_user_id',
                recipientName: 'Test User',
              ),
            ),
          ),
        ),
      );

      await tester.pumpAndSettle();

      // 验证加载指示器在处理状态下显示
      expect(find.byType(CircularProgressIndicator), findsNothing);
    });
  });
}
